﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Htss.Platform.Web
{
    public class VerifyField
    {
        private List<VerifyItem> _verifyItem = new List<VerifyItem>();
        public VerifyField() { }
        public VerifyField(string inputText,string fieldName)
        {
            InputText = inputText;
            FieldName = fieldName;
        }
        public List<VerifyItem> itemList { get { return _verifyItem; } }
        /// <summary>
        /// 需要验证的字段值
        /// </summary>
        public string InputText
        {
            get;
            set;
        }
        /// <summary>
        /// 需要验证的字段名
        /// </summary>
        public string FieldName
        {
            get;
            set;
        }
        /// <summary>
        /// 空验证
        /// </summary>
        /// <param name="byText">通过提示文本</param>
        /// <param name="errorText">异常提示文本</param>
        public void AddNull(string errorText)
        {
            VerifyItem item = new VerifyItem();
            item.VerifyType = VerifyType.Null;
            item.ByText = "";
            item.ErrorText = errorText;
            _verifyItem.Add(item);
        }
        /// <summary>
        /// 长度范围验证
        /// </summary>
        /// <param name="byText">通过提示文本</param>
        /// <param name="errorText">异常提示文本</param>
        /// <param name="minLength">最小长度</param>
        /// <param name="maxLength">最大长度</param>
        public void AddLengthRange( string errorText, int minLength, int maxLength)
        {
            VerifyItem item = new VerifyItem();
            item.VerifyType = VerifyType.LengthRange;
            item.ByText = "";
            item.ErrorText = errorText;
            item.MinLength = minLength;
            item.MaxLength = maxLength;
            _verifyItem.Add(item);
        }
        /// <summary>
        /// 比较验证
        /// </summary>
        /// <param name="byText">通过提示文本</param>
        /// <param name="errorText">异常提示文本</param>
        /// <param name="compareText">需要比较的值</param>
        public void AddCompare( string errorText, string compareText)
        {
            VerifyItem item = new VerifyItem();
            item.VerifyType = VerifyType.Compare;
            item.ByText = "";
            item.ErrorText = errorText;
            item.CompareText = compareText;
            _verifyItem.Add(item);
        }
        /// <summary>
        /// 正则验证
        /// </summary>
        /// <param name="byText">通过提示文本</param>
        /// <param name="errorText">异常提示文本</param>
        /// <param name="regexText">正则文本</param>
        public void AddRegex( string errorText, string regexText)
        {
            VerifyItem item = new VerifyItem();
            item.VerifyType = VerifyType.Regex;
            item.ByText = "";
            item.ErrorText = errorText;
            item.RegexText = regexText;
            _verifyItem.Add(item);
        }
        /// <summary>
        /// 自定义验证
        /// </summary>
        /// <param name="byText">通过提示文本</param>
        /// <param name="errorText">异常提示文本</param>
        /// <param name="customResult">自定义验证结果(True为通过,False为异常)</param>
        public void AddCustom(string errorText, bool customResult)
        {
            VerifyItem item = new VerifyItem();
            item.VerifyType = VerifyType.Custom;
            item.ByText = "";
            item.ErrorText = errorText;
            item.Custom = customResult;
            _verifyItem.Add(item);
        }
    }
}
